package cn.zlj.pethome.basic.rocketmq.consumer;

import cn.zlj.pethome.basic.domain.Logininfo;
import cn.zlj.pethome.basic.util.LoginContext;
import cn.zlj.pethome.order.domain.OrderPetAcquisition;
import cn.zlj.pethome.order.service.IOrderPetAcquisitionService;
import cn.zlj.pethome.org.domain.TEmployee;
import cn.zlj.pethome.org.mapper.EmployeeMapper;
import cn.zlj.pethome.pet.mapper.SearchMasterMsgMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Component
@RocketMQMessageListener(topic = "springboot_group",
        consumerGroup = "order"
        //, selectorExpression = "*",                   // 3.tag：设置为 * 时，表示全部。
       // messageModel = MessageModel.CLUSTERING    // 4.消费模式：默认 CLUSTERING （ CLUSTERING：负载均衡 ）（ BROADCASTING：广播
      )
@Slf4j
public class ConsumerOrder implements RocketMQListener<String> {
    @Autowired
    private IOrderPetAcquisitionService orderPetAcquisitionService;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public void onMessage(String id) {
        Long oid = Long.parseLong(id);
        OrderPetAcquisition order = orderPetAcquisitionService.findById(oid);
        Date date = new Date();
        if(order!=null&&order.getLastConfirmTime().getTime()<date.getTime()){
         //取消订单
       //HttpServletRequest request =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        orderPetAcquisitionService.cancel(order.getId(), null);
        }

    }
}
